package machine.api;

import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import org.springframework.stereotype.Service;

/**
 * 智能聊天api
 * http://api.qingyunke.com/
 *
 * @author zhanghui145
 * @date 2021/12/31 14:34
 * @since 1.0.0
 */
@Service
public class ChatAIApi {

    private static final String URI = "http://api.qingyunke.com/api.php?key=free&appid=0&msg=";

    public String replyMsg(String msg) {
        JSONObject object = JSONUtil.parseObj(HttpRequest.get(URI + msg).execute().body());
        if (((int)object.get("result")) != 0) {
            return "服务器卡住啦~";
        }
        return (String) object.get("content");
    }
}
